package com.powernode.settings.controller;

import com.powernode.commons.utils.ResponseData;
import com.powernode.settings.bean.Permission;
import com.powernode.settings.service.PermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("permission")
@Api(tags = "权限管理")
public class PermissionController {
    @Autowired
    private PermissionService service;

    @GetMapping
    @ApiOperation("获取所有的树形菜单")
    public ResponseData getAll(){
        return service.findAll();
    }


    @GetMapping("getPermissionIdsByRoleId")
    @ApiOperation("根据角色id查询权限")
    public ResponseData getPermissionIdsByRoleId(String roleId){
        return service.findPermissionIdByRoleId(roleId);
    }

    @PutMapping("editRolePermission")
    @ApiOperation("重新分配角色的权限")
    public ResponseData editRolePermission(String roleId,String permissionIds){
       /* System.out.println(roleId);
        System.out.println(permissionIds);*/
        return service.modifyRolePermission(roleId,permissionIds);
    }

    @PostMapping
    @ApiOperation("添加权限")
    public ResponseData add(@RequestBody Permission p){
        return service.add(p);

    }

    @PutMapping
    @ApiOperation("修改权限")
    public ResponseData edit(@RequestBody Permission p){
        return service.edit(p);

    }
    @DeleteMapping
    @ApiOperation("批量删除权限")
    public ResponseData deleteBatch(String ids){
        return service.removeBatch(ids);
    }


    @GetMapping("getPermissionsByUserId")
    @ApiOperation("根据用户id查询权限")
    public ResponseData getPermissionsByUserId(String userId){
        return service.findPermissionsByUserId(userId);
    }
}
